package hw;

import Util.FIleUtil;

import Util.Util;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class Atm extends JFrame {
    private Image bgimg = Util.getImage("/background.jpg");
    private Usercollection usercol = (Usercollection) FIleUtil.readObject("usercol.dat");
    private ArrayList<Users> useList = usercol.getUseList();
    private Login login = new Login(this);
    private Menu menu = new Menu(this);
    private Save save = new Save(this);
    private Find find = new Find(this);
    private Get get = new Get(this);
    private Changepw changepw = new Changepw(this);
    private Changemoney changemoney = new Changemoney(this);
    private CardLayout cardLayout = new CardLayout();

    private Users user;
    private int index;

    public Usercollection getUsercol() {
        return usercol;
    }

    public void setUsercol(Usercollection usercol) {
        this.usercol = usercol;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public Find getFind() {
        return find;
    }

    public void setFind(Find find) {
        this.find = find;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Login getLogin() {
        return login;
    }

    public void setLogin(Login login) {
        this.login = login;
    }

    public Menu getMenu() {
        return menu;
    }

    public void setMenu(Menu menu) {
        this.menu = menu;
    }

    public ArrayList<Users> getUseList() {
        return useList;
    }

    public void setUseList(ArrayList<Users> useList) {
        this.useList = useList;
    }

    //#############################       构建函数    ################################
    public Atm() {

        //#############################       这界面背景    ################################

        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgimg, 0, 0, 1100, 650, this);
            }
        });
        //#############################     添加组件      ################################
        this.setLayout(cardLayout);
        this.add("login", login);
        this.add("menu", menu);
        this.add("save", save);
        this.add("get", get);
        this.add("find", find);
        this.add("change", changepw);
        this.add("changeM", changemoney);


        //#############################       配置主界面       ####################################
        this.setSize(1100, 650);//设置大小
        this.setTitle("测试窗口");//设置标题
        this.setLocationRelativeTo(null);//设置窗口居中
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口关闭时程序结
        this.setVisible(true);//设置窗体可见
    }


    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }


    public static void main(String[] args) {
//        Usercollection us = new Usercollection();
//        us.getUseList().add( new Users("zs","1",1000));
//        us.getUseList().add( new Users("ls","2",2000));
//        us.getUseList().add( new Users("ww","3",3000));
//        FIleUtil.writeObject("usercol.dat",us);
        Atm atm= new Atm();


    }
}
